package com.huikeportal.service.impl;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huikeportal.dao.FootfallGlobalMapper;
import com.huikeportal.dao.SquareWeatherMapper;
import com.huikeportal.model.ReportGraphData;
import com.huikeportal.model.ReportWeatherData;
import com.huikeportal.model.SettingsHolidays;
import com.huikeportal.model.SiteAllInfo;
import com.huikeportal.service.FootfallGlobalService;
import com.huikeportal.service.SquareWeatherService;
import com.huikeportal.service.TodayIndexesService;

/**
 * @deprecated
 * @author wenyp
 *	星期对比
 */
@Service("SquareWeatherService")
public class SquareWeatherServiceImpl implements SquareWeatherService{
	
	
	@Autowired
	private SquareWeatherMapper squareWeatherMapper;
	
	@Autowired
	private TodayIndexesService todayIndexesService;
	
	@Autowired
	private FootfallGlobalService footfallGlobalService;
	
	@Autowired
	private FootfallGlobalMapper footfallGlobalMapper;
	
	
	/**
	 * 查询图表数据
	 * @param map
	 * @return List<ReportGraphData>
	 * @throws ParseException
	 */
	@SuppressWarnings("unchecked")
	public HashMap<String,Object> getGraphData(HashMap<String, Object> map)  throws Exception{
		List<ReportWeatherData> resultList=new ArrayList<ReportWeatherData>();
		//依据登陆用户信息查询用户场所
//		SiteAllInfo siteAllInfo=selectSiteByUserId((UserInfo)map.get("userInfo"));
		
		String timeType="";
		if(map.get("timeType")!=null && !map.get("timeType").toString().equals("")){
			timeType=map.get("timeType").toString();
		}
		String timeType_table="";
		if(map.get("timeType_table")!=null && !map.get("timeType_table").toString().equals("")){
			timeType_table=map.get("timeType_table").toString();
		}
		String startDate="";
		String endDate="";
		String from="";
		if(map.get("startDate")!=null && !map.get("startDate").toString().equals("")){
			from=map.get("startDate").toString();
		}
		String to="";
		if(map.get("endDate")!=null && !map.get("endDate").toString().equals("")){
			to=map.get("endDate").toString();
		}
		String type="";
		if(map.get("type")!=null && !map.get("type").toString().equals("")){
			type=map.get("type").toString();
		}
		String siteId="";
		if(map.get("siteId")!=null && !map.get("siteId").toString().equals("")){
			siteId=map.get("siteId").toString();
		}
		/**
		 * 判断siteId的sourse字段是否为1，如果为1，则cityId为旧的，如果不为1则为新的需要根据新旧城市代码对应成旧的城市id查找天气
		 */
		SiteAllInfo siteAllInfo=null;
		int Source = 0 ;
		if(siteId!=null&&!"".equals(siteId)){
			siteAllInfo = footfallGlobalMapper.selectSiteAllInfoById(siteId);
			Source = siteAllInfo.getSource();
		}
		
		HashMap<String,Object> typeMap =footfallGlobalService.getCalret(Integer.parseInt(type));
		HashMap<String, Object> pramMap1=getparam(timeType,from,to);
		List<String> listDate=(List<String>)pramMap1.get("Betweens");
		List<HashMap<String, Object>> pramMapTemp = getTemppramMap(pramMap1);

		for(int i = 0;i<pramMapTemp.size();i++){
			HashMap<String, Object> pramMapchild = pramMapTemp.get(i);
			pramMapchild.put("siteid",siteId);//放入场所id
			pramMapchild.put("calret", typeMap.get("calret"));
			pramMapchild.put("ziduan", typeMap.get("ziduan"));
			List<String> listDate1 = (List<String>) pramMapchild.get("Betweens");
			String tableList =getSelectTables(listDate1);
			pramMapchild.put("table2", tableList);
			List<ReportWeatherData> resultListChild;
			if(Source == 1){
				resultListChild =squareWeatherMapper.selectWeatherDataGraph1(pramMapchild);
			}else{
				resultListChild =squareWeatherMapper.selectWeatherDataGraph(pramMapchild);	
			}
			
			resultList.addAll(resultListChild);
		}
		

		
		HashMap<String, List<String>> getTubiaoDate = getTubiaoDate(type,resultList,listDate);
		HashMap<String, String> pieData=getPieDate(resultList);
		HashMap<String,  List<String>> weekWeaherDate=getWeekWeaherDate(type,resultList);
		HashMap<String, Object> historyWeatherData=getHistoryWeatherData(type,resultList,listDate);
		HashMap<String,Object> resultMap=new HashMap<String,Object>();
		resultMap.put("resultList",resultList);
		resultMap.put("getTubiaoDate",getTubiaoDate);
		resultMap.put("pieData",pieData);
		resultMap.put("weekWeaherDate",weekWeaherDate);
		resultMap.put("historyWeatherData",historyWeatherData);
		
		String siteN= footfallGlobalService.getSiteNames(siteId);
		resultMap.put("siteN", siteN);
		resultMap.put("stadubiao", listDate.get(0));
		resultMap.put("endtubiao", listDate.get(listDate.size()-1));
		
		
		
		return resultMap;
	}
	
	
	private List<HashMap<String, Object>> getTemppramMap(HashMap<String, Object> pramMap1){
		
		List<String> Betweens = (List<String>) pramMap1.get("Betweens");
		List<HashMap<String, Object>> pramMapTemp = new ArrayList<HashMap<String,Object>>();
		for(String date:Betweens){
			SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
			Date dateFrom;
			int year = 0;
			try {
				dateFrom = sf.parse(date);
				year = dateFrom.getYear();
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			boolean ifAdd = true;
			int index = 0;
			for(int i = 0;i<pramMapTemp.size();i++){
				HashMap<String, Object> mapd = pramMapTemp.get(i);
				int	MaptempYear = Integer.parseInt(mapd.get("year").toString());
				if(year == MaptempYear){
					ifAdd = false;
					index = i; 
				}
			}
			if(ifAdd){//还没有年分组需要加入
				HashMap<String, Object> mapadd = new HashMap<String, Object>();
				mapadd.put("year", year);
				List<String> datAdd = new ArrayList<String>();
				datAdd.add(date);
				mapadd.put("Betweens", datAdd);
				pramMapTemp.add(mapadd);
			}else{//已经有年的分组不需要加入
				HashMap<String, Object> mapadd = pramMapTemp.get(index);
				List<String> datAdd = (List<String>) mapadd.get("Betweens");
				datAdd.add(date);
				mapadd.put("Betweens", datAdd);
			}
		}
		//给分组的对象加入开始时间结束时间
		for(int i1 = 0;i1<pramMapTemp.size();i1++){
			HashMap<String, Object> pramMapTempch = pramMapTemp.get(i1);
			List<String> datchAdd  = (List<String>) pramMapTempch.get("Betweens");
			String startDate1 =  datchAdd.get(0);
			String endDate1 =  datchAdd.get(datchAdd.size()-1);
			pramMapTempch.put("startDate", startDate1);
			pramMapTempch.put("endDate", endDate1);
		}
		return pramMapTemp;
		
	}
	/**
	 * 根据要查询的事件段获取需要的天气数据表，本年为settings_weather，上一年为2014年
	 * 表为settings_weather_2014，上一年为 YEAR 表就为settings_weather_+YEAR
	 * @param listDate
	 * @return
	 */
	private String getSelectTables(List<String> listDate){ 
		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
		String endDatestr = listDate.get(0);
		Date endDate=new Date();
		try {
			endDate=sf.parse(endDatestr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		Calendar today = Calendar.getInstance();
		today.setTime(new Date());
		Calendar endDay = Calendar.getInstance();
		endDay.setTime(endDate);
		
		int todayYear=today.get(Calendar.YEAR);
		int endYear=endDay.get(Calendar.YEAR);
		String endTable = "";
		if(endYear==todayYear){
			endTable="settings_weather";
		}else{
			endTable="settings_weather_"+endYear;
		}
		
		return endTable;
		/*
		 * 根据要查询的事件段获取需要的天气数据表，本年为settings_weather，上一年为2014年
		 * 表为settings_weather_2014，上一年为 YEAR 表就为settings_weather_+YEAR
		 * @param listDate
		 * @return
		String begainTable="";
		String endTable="";
		String begain= listDate.get(0);
		String end=listDate.get(listDate.size()-1);
		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
		
		Date begainDate=new Date();
		Date endDate=new Date();
		
		try {
			begainDate = sf.parse(begain);
			endDate=sf.parse(end);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		Calendar today = Calendar.getInstance();
		today.setTime(new Date());
		Calendar endDay = Calendar.getInstance();
		endDay.setTime(endDate);
		Calendar begainDay = Calendar.getInstance();
		begainDay.setTime(begainDate);
		
		int todayYear=today.get(Calendar.YEAR);
		int endYear=endDay.get(Calendar.YEAR);
		int begainYear=begainDay.get(Calendar.YEAR);
		
		if(endYear==todayYear){
			endTable="settings_weather";
		}else{
			endTable="settings_weather_"+endYear;
		}
		
		if(begainYear==todayYear){
			begainTable="settings_weather";
		}else{
			begainTable="settings_weather_"+begainYear;
		}
		if(begainTable.endsWith(endTable)){
			begainTable = "";
		}
		
		List<String> tableList=new ArrayList<String>();
		tableList.add(begainTable);
		tableList.add(endTable);
		
		
		return tableList;
		*/
		
	}
	/**
	 * 历史指标天气分析
	 * @param resultList
	 * @param listDate
	 * @return HashMap<String, Object>
	 * @throws Exception
	 */
	private  HashMap<String, Object> getHistoryWeatherData(String type,List<ReportWeatherData> resultList,List<String> listDate) throws Exception{
		List<ReportWeatherData> result=resultList;
		
		String indexName = footfallGlobalService.getOrderField(type);
		if(result.size()!=listDate.size()){
			for (int da=0;da<listDate.size();da++){
				Boolean flg=false;
				for(int rep=0;rep< result.size();rep++){
					if(listDate.get(da).equals(result.get(rep).getDatatime())){
						flg=true;
					}
				}
				if(flg){
					continue;
				}else{
				ReportWeatherData reportWeatherData=new ReportWeatherData();
				reportWeatherData.setDatatime(listDate.get(da));
				result.add(da, reportWeatherData);
				}
			}
		}
		
		double total=0;
		double totalData=0;
		String avg="";
		for(ReportWeatherData reportWeatherData:result){
			Object dateNumber = (footfallGlobalService.getIndexData(reportWeatherData,indexName)==null)?0:footfallGlobalService.getIndexData(reportWeatherData,indexName);
			double dataBumberStr = Double.parseDouble(dateNumber.toString());
			total++;
			totalData=totalData + dataBumberStr;
		}
		if(total==0){
			avg="0";
		}else{
			avg=String.valueOf(Math.round(totalData/total));
		}
		
		HashMap<String, Object> resultMap=new HashMap<String, Object>();
		resultMap.put("data",result );
		resultMap.put("avg",avg );
		
		return resultMap;
		
		
		
	}
	
	
	/**
	 * 天气星期对比分析
	 * @param resultList
	 * @return
	 * @throws Exception
	 */
	private  HashMap<String, List<String>> getWeekWeaherDate(String type,List<ReportWeatherData> resultList) throws Exception{
		
		
		String indexName = footfallGlobalService.getOrderField(type);
		//平均客流list
		List<HashMap<String, Object>> weekList1 =new ArrayList<HashMap<String, Object>>();
		List<HashMap<String, Object>> weekList2 =new ArrayList<HashMap<String, Object>>();
		List<HashMap<String, Object>> weekList3 =new ArrayList<HashMap<String, Object>>();
		List<HashMap<String, Object>> weekList4 =new ArrayList<HashMap<String, Object>>();
		List<HashMap<String, Object>> weekList5 =new ArrayList<HashMap<String, Object>>();
		List<HashMap<String, Object>> weekList6 =new ArrayList<HashMap<String, Object>>();
		List<HashMap<String, Object>> weekList7 =new ArrayList<HashMap<String, Object>>();
		
		for(ReportWeatherData reportWeatherData :resultList){
			
			Object dateNumber = (footfallGlobalService.getIndexData(reportWeatherData,indexName)==null)?0:footfallGlobalService.getIndexData(reportWeatherData,indexName);
			double dataBumberStr = Double.parseDouble(dateNumber.toString());
			
			if(reportWeatherData.getCategoryID()==null || "".endsWith(reportWeatherData.getCategoryID())){
				continue;
			}
			SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
			Date date=sf.parse(reportWeatherData.getDatatime());
			Integer week = getDayOfWeek(date);
			HashMap<String, Object> maptm =new HashMap<String, Object>();
			if("1".endsWith(reportWeatherData.getCategoryID())){//1晴天
				maptm.put("weather", "1");
				maptm.put("data", dataBumberStr);
			}else if("2".endsWith(reportWeatherData.getCategoryID())){//2阴天
				maptm.put("weather", "2");
				maptm.put("data", dataBumberStr);
				
			}else if("3".endsWith(reportWeatherData.getCategoryID())){//3雨天
				maptm.put("weather", "3");
				maptm.put("data", dataBumberStr);
			}else if("4".endsWith(reportWeatherData.getCategoryID())){//4雨雪
				maptm.put("weather", "4");
				maptm.put("data", dataBumberStr);
			}
			if(week==1){//周日
				weekList1.add(maptm);
			}else if(week==2){//周1
				weekList2.add(maptm);
			}else if(week==3){//周2
				weekList3.add(maptm);
			}else if(week==4){//周3
				weekList4.add(maptm);
			}else if(week==5){//周4
				weekList5.add(maptm);
			}else if(week==6){//周5
				weekList6.add(maptm);
			}else{//周6
				weekList7.add(maptm);
			}
		}
		
		List<String> List1=getWeatherWeek(weekList1);
		List<String> List2=getWeatherWeek(weekList2);
		List<String> List3=getWeatherWeek(weekList3);
		List<String> List4=getWeatherWeek(weekList4);
		List<String> List5=getWeatherWeek(weekList5);
		List<String> List6=getWeatherWeek(weekList6);
		List<String> List7=getWeatherWeek(weekList7);
		
		HashMap<String, List<String>> resultMap=new HashMap<String, List<String>>();
		resultMap.put("zhouri", List1);
		resultMap.put("zhouyi", List2);
		resultMap.put("zhouer", List3);
		resultMap.put("zhousan", List4);
		resultMap.put("zhousi", List5);
		resultMap.put("zhouwu", List6);
		resultMap.put("zhouliu", List7);
		return resultMap;
		
	}
	
	private  List<String> getWeatherWeek(List<HashMap<String, Object>> weekList) throws Exception{
		
		double sunnyTimes=0;
		double sunnyData=0;
		double cloudyTimes=0;
		double cloudyData=0;
		double rainTimes=0;
		double rainData=0;
		double snowTimes=0;
		double snowData=0;
		
		for(HashMap<String, Object> map :weekList){
			double intd = Double.valueOf((map.get("data")==null?0:map.get("data")).toString());
			
			if("1".equals((String) map.get("weather"))){
				sunnyTimes++;
				sunnyData=sunnyData+ intd;
			}else if("2".equals((String) map.get("weather"))){
				cloudyTimes++;
				cloudyData=cloudyData+ intd;
			}else if("3".equals((String) map.get("weather"))){
				rainTimes++;
				rainData=rainData+ intd;
			}else{
				snowTimes++;
				snowData=snowData+ intd;
			}
		}
		
		List<String> resultList=new ArrayList<String>();
		if(sunnyTimes!=0){
		resultList.add(String.valueOf(Math.round(sunnyData/sunnyTimes)));
		}else{
			resultList.add("0");
		}
		if(cloudyTimes!=0){
		resultList.add(String.valueOf(Math.round(cloudyData/cloudyTimes)));
		}else{
			resultList.add("0");
		}
		if(rainTimes!=0){
		resultList.add(String.valueOf(Math.round(rainData/rainTimes)));
		}else{
			resultList.add("0");
		}
		if(snowTimes!=0){
		resultList.add(String.valueOf(Math.round(snowData/snowTimes)));
		}else{
			resultList.add("0");
		}
		return resultList;
	}
	

	/**
	 * 广场天气分析pie图数据
	 * @param resultList
	 * @return
	 * @throws Exception
	 */
	private  HashMap<String, String> getPieDate(List<ReportWeatherData> resultList) throws Exception{
		//平均客流list
		Integer sunnyTimes=0;
		Integer cloudyTimes=0;
		Integer rainTimes=0;
		Integer snowTimes=0;
		
		for(ReportWeatherData reportWeatherData :resultList){
			if(reportWeatherData.getCategoryID()==null || "".equals((reportWeatherData.getCategoryID()))){
				continue;
			}
			
			//平均客流
			if("1".endsWith(reportWeatherData.getCategoryID())){//1晴天
				sunnyTimes++;
			}else if("2".endsWith(reportWeatherData.getCategoryID())){//2阴天
				cloudyTimes++;
			}else if("3".endsWith(reportWeatherData.getCategoryID())){//3雨天
				rainTimes++;
			}else if("4".endsWith(reportWeatherData.getCategoryID())){//4雨雪
				snowTimes++;
			}
		}
		
		HashMap<String, String> resultMap=new HashMap<String, String>();
		resultMap.put("sunnyTimes", sunnyTimes.toString());
		resultMap.put("cloudyTimes", cloudyTimes.toString());
		resultMap.put("rainTimes", rainTimes.toString());
		resultMap.put("snowTimes", snowTimes.toString());
		return resultMap;
		
	}
	
	/**
	 * 广场天气分析指标天气对比分析图数据
	 * @param resultList
	 * @return
	 * @throws Exception
	 */
	private  HashMap<String, List<String>> getTubiaoDate(String type,List<ReportWeatherData> resultList,List<String> listDate) throws Exception{
		
		String indexName = footfallGlobalService.getOrderField(type);
		//平均客流list
		List<Double> avgSunnyList=new ArrayList<Double>();
		List<Double> avgCloudyList=new ArrayList<Double>();
		List<Double> avgRainList=new ArrayList<Double>();
		List<Double> avgSnowList=new ArrayList<Double>();
		//周末客流list
		List<Double> weekSunnyList=new ArrayList<Double>();
		List<Double> weekCloudyList=new ArrayList<Double>();
		List<Double> weekRainList=new ArrayList<Double>();
		List<Double> weekSnowList=new ArrayList<Double>();
		//工作日客流list
		List<Double> workSunnyList=new ArrayList<Double>();
		List<Double> workCloudyList=new ArrayList<Double>();
		List<Double> workRainList=new ArrayList<Double>();
		List<Double> workSnowList=new ArrayList<Double>();
		//1	晴天2	阴天3	雨天4	雨雪
		/**
		 * 依据数据的起始结束时间获取假期日期
		 * dates 字符串日期
		 * settingsHolidays 假期
		 * 
		 */
		String dates = "";
		for (String date : listDate) {
			dates = dates + "'" + date + "'" + ",";
		}
		dates = dates.substring(0, dates.length() - 1);
		HashMap<String, String> daoParam = new HashMap<String, String>();
		daoParam.put("dates", dates);
		List<SettingsHolidays> settingsHolidays = squareWeatherMapper.selectHolidaysByParaMap(daoParam);
		//获取假期日期结束
		
		for(ReportWeatherData reportWeatherData :resultList){
			if(reportWeatherData.getCategoryID()==null || "".endsWith(reportWeatherData.getCategoryID())){
				continue;
			}
			Object dateNumber = (footfallGlobalService.getIndexData(reportWeatherData,indexName)==null)?0:footfallGlobalService.getIndexData(reportWeatherData,indexName);
			double dataBumberStr = Double.parseDouble(dateNumber.toString());
			
			
			
			//平均客流
			if("1".endsWith(reportWeatherData.getCategoryID())){//1晴天
				avgSunnyList.add(dataBumberStr);
			}else if("2".endsWith(reportWeatherData.getCategoryID())){//2阴天
				avgCloudyList.add(dataBumberStr);
			}else if("3".endsWith(reportWeatherData.getCategoryID())){//3雨天
				avgRainList.add(dataBumberStr);
			}else if("4".endsWith(reportWeatherData.getCategoryID())){//4雨雪
				avgSnowList.add(dataBumberStr);
			}
			SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
			
			Date date=sf.parse(reportWeatherData.getDatatime());
			if( isWeekend (date)||settingsHolidays.contains(reportWeatherData.getDatatime())){//如果是周末或者是节假日
				if("1".endsWith(reportWeatherData.getCategoryID())){//1晴天
					weekSunnyList.add(dataBumberStr);	
				}else if("2".endsWith(reportWeatherData.getCategoryID())){//2阴天
					weekCloudyList.add(dataBumberStr);	
				}else if("3".endsWith(reportWeatherData.getCategoryID())){//3雨天
					weekRainList.add(dataBumberStr);	
				}else if("4".endsWith(reportWeatherData.getCategoryID())){//4雨雪
					weekSnowList.add(dataBumberStr);
				}
			}else{//工作日
				if("1".endsWith(reportWeatherData.getCategoryID())){//1晴天
					workSunnyList.add(dataBumberStr);
				}else if("2".endsWith(reportWeatherData.getCategoryID())){//2阴天
					workCloudyList.add(dataBumberStr);
				}else if("3".endsWith(reportWeatherData.getCategoryID())){//3雨天
					workRainList.add(dataBumberStr);
				}else if("4".endsWith(reportWeatherData.getCategoryID())){//4雨雪
					workSnowList.add(dataBumberStr);
				}
			}
		}
		
		List<String> avgList=new ArrayList<String>();
		avgList.add(getListAvg(avgSunnyList));
		avgList.add(getListAvg(avgCloudyList));
		avgList.add(getListAvg(avgRainList));
		avgList.add(getListAvg(avgSnowList));
		
		List<String> WeekList=new ArrayList<String>();
		WeekList.add(getListAvg(weekSunnyList));
		WeekList.add(getListAvg(weekCloudyList));
		WeekList.add(getListAvg(weekRainList));
		WeekList.add(getListAvg(weekSnowList));
		
		List<String> workList=new ArrayList<String>();
		workList.add(getListAvg(workSunnyList));
		workList.add(getListAvg(workCloudyList));
		workList.add(getListAvg(workRainList));
		workList.add(getListAvg(workSnowList));
		
		HashMap<String, List<String>> resultMap=new HashMap<String, List<String>>();
		resultMap.put("avgList",avgList);
		resultMap.put("WeekList",WeekList);
		resultMap.put("workList",workList);
		return resultMap;
	}
	
	
	public String getListAvg(List<Double> list){
		Double sum=0.0;
		//如果list为空直接返回0，如果不为空计算平均值
		if(list.size()==0){return String.valueOf(0);}
		for(Double in:list){
			sum=sum+(in==null?0:in);
		}
		return String.valueOf((Math.round(sum/list.size())));
		
	}
	
	/**
	  * 得到数据起始结束时间、及时间点list
	  * @return HashMap<String, Object>
	 * @throws ParseException 
	  */
	public HashMap<String, Object> getparam(String timeType,String from,String to) throws ParseException{
		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
		HashMap<String, Object> resultMap = new HashMap<String, Object>();
	
		//根据timeType计算查询几天的数据
		if(timeType.equals("0")){
			Date dateFrom= sf.parse(from);
			Date dateTo= sf.parse(to);
			resultMap.put("startDate",sf.format(dateFrom));
			resultMap.put("endDate", sf.format(dateTo));
		}else if(timeType.equals("30")){
			Date date=new Date();
			String endDate=sf.format(date);
			date.setDate(date.getDate()-30);
			String startDate=sf.format(date);
			resultMap.put("startDate", startDate);
			resultMap.put("endDate", endDate);
		}else if(timeType.equals("60")){
			Date date=new Date();
			String endDate=sf.format(date);
			date.setDate(date.getDate()-60);
			String startDate=sf.format(date);
			resultMap.put("startDate", startDate);
			resultMap.put("endDate", endDate);
		}else if(timeType.equals("90")){
			Date date=new Date();
			String endDate=sf.format(date);
			date.setDate(date.getDate()-90);
			String startDate=sf.format(date);
			resultMap.put("startDate", startDate);
			resultMap.put("endDate", endDate);
		}
		//根据开始时间结束时间算出时间段
		List<String> listDate=footfallGlobalService.getDatesBetweenTwoDate(resultMap.get("startDate").toString(),resultMap.get("endDate").toString());
		resultMap.put("Betweens", listDate);
	
		return resultMap;
	}
	
	 /**
	  * 判断一个日期是否日节假日 法定节假日只判断月份和天，不判断年
	  * 
	  * @param date
	  * @return
	  */
	 public boolean isFestival(Date date) {
	  boolean festival = false;
	  Calendar fcal = Calendar.getInstance();
	  Calendar dcal = Calendar.getInstance();
	  dcal.setTime(date);
//	  List<Date> list = this.getFestival();
//	  for (Date dt : list) {
//	   fcal.setTime(dt);
//
//	   // 法定节假日判断
//	   if (fcal.get(Calendar.MONTH) == dcal.get(Calendar.MONTH)
//	     && fcal.get(Calendar.DATE) == dcal.get(Calendar.DATE)) {
//	    festival = true;
//	   }
//	  }
	  return festival;
	 }

	 /**
	  * 周六周日判断
	  * 
	  * @param date
	  * @return
	  */
	 public boolean isWeekend(Date date) {
	  boolean weekend = false;
	  Calendar cal = Calendar.getInstance();
	  cal.setTime(date);
	  if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
	    || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
	   weekend = true;
	  }
	  return weekend;
	 }

	 private Integer getDayOfWeek(Date date){
		 Integer dayOfWeek;
		 Calendar cal = Calendar.getInstance();
		  cal.setTime(date);
		  dayOfWeek= cal.get(Calendar.DAY_OF_WEEK);
		  return dayOfWeek;
	 }
	 /**
	  * 是否是工作日 法定节假日和周末为非工作日
	  * 
	  * @param date
	  * @return
	  */
	 public boolean isWorkDay(Date date) {
	  boolean workday = true;
	  if (this.isFestival(date) || this.isWeekend(date)) {
	   workday = false;
	  }
	  return workday;
	 }
	
}
